package org.big.rocktproducer.hard;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class RocketMQProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    
    // 发送简单消息
    public void sendMessage(String topic, String message) {
        rocketMQTemplate.convertAndSend(topic, message);
    }
    
    // 发送带标签的消息
    public void sendTagMessage(String topic, String tag, Object payload) {
        rocketMQTemplate.convertAndSend(topic + ":" + tag, payload);
    }
    
    // 发送延迟消息
    public void sendDelayMessage(String topic, Object payload, int delayLevel) {
        rocketMQTemplate.syncSend(topic, MessageBuilder.withPayload(payload).build(),
                                3000, delayLevel);
    }
}